#include"Process.h"
#define SIZE 101
#define FLAG '='
//进度条demo
void process(){
    int rate = 0;
    char buffer[SIZE];
    memset(buffer,0,sizeof(buffer));
    const char* l = "-\\|/";
    int len = strlen(l);
    while(rate<=100){
        printf("[%-100s][%d%%][%c]\r",buffer,rate,l[rate%len]);
        fflush(stdout);
        buffer[rate]=FLAG;
        usleep(100000);
        rate++;
    }
    printf("\n");
}

void fflushprocess(const char* s,double cur,double total){
    const char* l = "-\\|/";
    char buffer[SIZE];
    memset(buffer,0,sizeof(buffer));
    double rate = cur*100.0/total;
    int num = (int)rate;
    int i =0;
    for(;i<num;i++){
        buffer[i]=FLAG;
    }
    int len = strlen(l);
    static int index = 0;
    printf("%s...[%-100s][%.1lf%%][%c]\r",s,buffer,rate,l[index++]);
    fflush(stdout);
    index%=len;
    if(num>=100)
        printf("\n");
}
